$(function(){
	$("input[disabled='true']").css({"border-color": "gray"});
});


/**

 * 改变行颜色
 */
function changeRowColor(obj)
{
	obj.style.backgroundColor="#F0F5FB";
}

/**
 * 恢复行颜色
 */
function resumeRowColor(obj,id)
{
//	alert();
	if(id==1)
		obj.style.backgroundColor="#F8F8F8";
		//obj.style.backgroundColor="#f5f5f6";
	else
		obj.style.backgroundColor="#FFFFFF";
}

/**
 * 根据表单内容得到参数字符串
 */
function serializeForm(form){
	var value = "";
	value = getElementsSerializeByTagName(form,value,"input");
	value = getElementsSerializeByTagName(form,value,"select");
	value = getElementsSerializeByTagName(form,value,"textarea");
	return value;
}

function getElementsSerializeByTagName(form,value,tagName){
	var inputs = form.getElementsByTagName(tagName);
	if(inputs != undefined){
		for(var i=0; i<inputs.length; ++i){
			var  s = getElementString(inputs[i]);
			if(s != ""){
				if(value != "")
					value +="&";
				value += s;
			}
		}
	}
	return value;
}

function getElementString(elem){
	if(elem.name==undefined || elem.name=='' || elem.name==null)
		return "";
	if(elem.type=="text")
		return elem.name+"="+encodeValue(elem.value);
	if(elem.type=="hidden")
		return elem.name+"="+encodeValue(elem.value);
	if(elem.type=="checkbox" && elem.checked)
		return elem.name+"="+encodeValue(elem.value);
	if(elem.type=="radio" && elem.checked)
		return elem.name+"="+encodeValue(elem.value);
	if(elem.type==undefined || elem.type==null)
		return elem.name+"="+encodeValue(elem.value);
	if(elem.type=="select-one")
		return elem.name+"="+encodeValue(elem.value);
	if(elem.type=="select-multiple"){
		var value = "";
		for(i=0;i<elem.length;i++){
			if(elem.options[i].selected){
				if(value !="")
					value+="&";
				value += elem.name+"="+encodeValue(elem.options[i].value);
			}
		}
		return value;
	}
	if(elem.type=="textarea")
		return elem.name+"="+encodeValue(elem.value);
	return "";
}

function encodeValue(value){
	var v = value.replace(/\=/g,"%3D").replace(/\?/g,"%3F").replace(/\&/g,"%26");
	return v;
}


//选择取消全部
function selectAll(check)
{
	var elems = document.getElementsByName("formMap.ids");
	for(var i=0;i<elems.length;++i)
	{
		if(check)
			elems[i].checked="checked";
		else
			elems[i].checked="";
	}
}

//选择取消全部
function isSelect()
{
	var len=0;
	var elems = document.getElementsByName("formMap.ids");
	for(var i=0;i<elems.length;++i)
	{
		if(elems[i].checked)
			len +=1;
	}
	return len;
}

function $$(id){
	return document.getElementById(id);
}

/**
 * 改变每页显示的记录数时，重新刷新页面
 */
function changePageSize(pageSize)
{
	
	 list($$("pageForm.pageNo").value);
	 
}

/**
 * 改变每页显示的记录数时，重新刷新页面
 */
function refresh(pageNo)
{
	if(pageNo<=0){
		pageNo=1;
	}
	$$("pageForm.pageNo").value = pageNo;
	if($$("formMap.searchKey")){
		listSearch(pageNo);
	}else{
		list(pageNo);
	}
}



//选择取消全部
function selectAll(check)
{
	var elems = document.getElementsByName("formMap.ids");
	for(var i=0;i<elems.length;++i)
	{
		if(check)
			elems[i].checked="checked";
		else
			elems[i].checked="";
	}
}

//选择取消全部
function isSelect()
{
	var len=0;
	var elems = document.getElementsByName("formMap.ids");
	for(var i=0;i<elems.length;++i)
	{
		if(elems[i].checked)
			len +=1;
	}
	return len;
}


/**
 * 初始化IFrame 数据
 */
function initParentIFrame() {
	var iframe = window.parent.document.getElementById("mainFrame");
	var leftDiv = window.parent.document.getElementById("contentDiv_left");
	var contentDiv_right = window.parent.document.getElementById("contentDiv_right");
	var contentDiv = window.parent.document.getElementById("contentDiv");
	var scrollModel = window.parent.document.getElementById("contentDiv_left_scrollModel_content");
	var height=741;
	iframe.height =  height;
	if(isIE6Version()) {
		contentDiv_right.style.height =  (height + 33) + "px";
	}else {
		contentDiv_right.style.height = height + "px";
		contentDiv.style.height = height + "px";
	}
	leftDiv.style.height = (height ) + "px";
	scrollModel.style.height = (height - 249) + "px";
	
	/*
	iframe.height = "741px";
	iframe.contentWindow.document.body.scrollHeight = "741px";
	iframe.contentWindow.document.documentElement.scrollHeight = "741px";
	leftDiv.style.height = "492px";
	scrollModel.style.height = "462px";
	contentDiv_right.style.height = "741px";
	contentDiv.style.height = "741px";
	*/
}



/**
 * 翻页
 */
function goPage(pageNo){
	if($$("pageForm.pageNo")!==undefined)
		$$("pageForm.pageNo").value = pageNo;
		
	if($$("formMap.searchKey")){
		listSearch(pageNo);
	}else{
		list(pageNo);
	}
	initParentIFrame();
}

function getDelParams(){
	var ids = document.getElementsByName("formMap.ids");
	var value = "";
	for(var i=0;i<ids.length;i++){
		var  s = getElementString(ids[i]);
		if(s != ""){
			if(value != "")
				value +="&";
			value += s;
		}
	}
	return value;
}
/*
 */
jQuery.extend({
  		 evalJSON: function(strJson) {
    		 return eval("(" + strJson + ")");
   			}
}); 
jQuery.extend({
   toJSON: function(object) {
     var type = typeof object;
     if ('object' == type) {
       if (Array == object.constructor) type = 'array';
       else if (RegExp == object.constructor) type = 'regexp';
       else type = 'object';
     }
     switch (type) {
     case 'undefined':
     case 'unknown':
       return;
       break;
     case 'function':
     case 'boolean':
     case 'regexp':
       return object.toString();
       break;
     case 'number':
       return isFinite(object) ? object.toString() : 'null';
       break;
     case 'string':
       return '"' + object.replace(/(\\|\")/g, "\\$1").replace(/\n|\r|\t/g, function() {
         var a = arguments[0];
         return (a == '\n') ? '\\n': (a == '\r') ? '\\r': (a == '\t') ? '\\t': ""
       }) + '"';
       break;
     case 'object':
       if (object === null) return 'null';
       var results = [];
       for (var property in object) {
         var value = jQuery.toJSON(object[property]);
         if (value !== undefined) results.push(jQuery.toJSON(property) + ':' + value);
       }
       return '{' + results.join(',') + '}';
       break;
     case 'array':
       var results = [];
       for (var i = 0; i < object.length; i++) {
         var value = jQuery.toJSON(object[i]);
         if (value !== undefined) results.push(value);
       }
       return '[' + results.join(',') + ']';
       break;
     }
   }
});
function multiChoice(flag,targetId,url,isSentDep){
	var url = url+"/sysmanage/dataDictionary.action?cmd=other&formMap.flag="+flag+"&formMap.targetId="+targetId+"&formMap.isSentDep="+isSentDep;
	if(flag=='reviewPeriod'){
		var obj = $$('po.id');
		if(obj){
			url = url+"&formMap.sourceId="+obj.value;
		}
	}
	 window.showModalDialog(url,window,"dialogWidth:700px;dialogHeight:520px;resizable:no;scrollbars:no;scroll:no", "menubar:no;toolbar:no;scrollbars:no;scroll:no");
}

String.prototype.trim = function()   
{   
return this.replace(/(^\s*)|(\s*$)/g, "");   
}   

function download(showName,path,attachmentName,url){
	path = encodeURIComponent(path);
	showName = encodeURIComponent(showName);
	attachmentName = encodeURIComponent(attachmentName);
	url = url+"/sysmanage/dataDictionary.action?cmd=download&formMap.path="+path+"&formMap.attachmentName="+attachmentName+"&formMap.showName="+showName;
	window.location.href = url;
}


function showSearchKey(obj){
	if(obj.value.indexOf("_sel")!=-1 || obj.value=='sentDep' || obj.value=='belongPlateFormID'){
		var url = "sysmanage/modules.action?cmd=change&formMap.changeFlag="+obj.id+"&formMap.modulesId="+obj.value;
		$.ajax({
			type: "POST",
			url: url,
			dateType: "html",
			success: function(returnedData){
				$$("searchKeyTd").innerHTML = returnedData;
			}
		});
	}else{
		initSearchKey();
	}
}

function initSearchKey(){
	$$("searchKeyTd").innerHTML = "";
	$("#searchKeyTd").append("<input type=\"text\" name=\"formMap.searchKey\" id=\"searchKey\" style=\"width: 110px;\" onkeydown=\"clickEnterSearch(event);\">");
	$("#searchKey").focus();
}

function clickEnterSearch(event)
{
    var eventObj=(event==null||event== undefined ) ? window.event : event;
    var keyCode = (eventObj.which) ? eventObj.which : eventObj.keyCode;
    if(keyCode == 13)
    {
        search();
    }
}

function searchSelect(obj){
	var id = getNextSelectTdId(obj.id);
	if(id==""){
		initSearchKey();
	}
	var modulesId = obj.value;
	if(obj.id=='tableNameSel'){
		var s = modulesId.indexOf("|");
		if(s>0)
		modulesId=modulesId.substring(0,modulesId.indexOf("|"));
	}
	var url = "sysmanage/modules.action?cmd=change&formMap.changeFlag="+obj.id
			+"&formMap.modulesId="+modulesId+"&formMap.nextFlag="+id+"Sel";
	if(modulesId==-1){
		return;
	}
	$.ajax({
		type: "POST",
		url: url,
		dateType: "html",
		success: function(returnedData){
			var tObj = $$(id);
			if(tObj){
				tObj.innerHTML = returnedData;
				var nextObj = $$(id+"Sel");
				if(nextObj){
					searchSelect(nextObj);
				}else{
					var goIndexObj = $$("goIndex");
					if(goIndexObj){
						goIndexObj.click();
					}else{
						initSearchKey();
					}
				}
			}else{
				var goIndexObj = $$("goIndex");
				if(goIndexObj){
					goIndexObj.click();
				}else{
					initSearchKey();
				}
			}
		}
	});
}



function getNextSelectTdId(id){
	var tdId = "";
	if(id=='typeSel'){
		tdId="childType";
	}else if(id=='childTypeSel'){
		tdId="tableName";
	}else if(id=='tableNameSel'){
		tdId="searchProperty";
	}
	return tdId;
}

String.prototype.replaceAll = function(s1,s2){   
	return this.replace(new RegExp(s1,"gm"),s2);   
}

function isIE6Version() {
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=b_version.split(";");
	var trim_Version=version[1].replace(/[ ]/g,"");
	if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0"){
		return true;
	} else {
		return false;
	}
	
}


function checkWebAddress(webSiteAdd) {
	var pattern=/^(http(s)?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
	if(!pattern.test(webSiteAdd)){
		alert("请输入正确的网址格式!如：http://www.baidu.com 或者：www.baidu.com");
		return true;
	}
	
}




function reinitIframe(){

var iframe = document.getElementById("mainFrame");
var leftDiv = document.getElementById("contentDiv_left");
var contentDiv_right = document.getElementById("contentDiv_right");
var contentDiv = document.getElementById("contentDiv");
var scrollModel = document.getElementById("contentDiv_left_scrollModel_content");

try{
//	iframe.height = "741px";
//	iframe.contentWindow.document.body.scrollHeight = "741px";
//	iframe.contentWindow.document.documentElement.scrollHeight = "741px";
//	leftDiv.style.height = "741px";
//	scrollModel.style.height = "700px";
//	contentDiv_right.style.height = "741px";
//	contentDiv.style.height = "500px";
	
	
	var bHeight = iframe.contentWindow.document.body.scrollHeight;
	
	var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
	
	var height = Math.max(bHeight, dHeight);
	
	//在此作测试
	//height = iframe.contentWindow.document.body.table;
	
	if(height < 741)
		height = 741;
	
	iframe.height =  height;

	if(height > 741) {
		
		if(isIE6Version()) {
			contentDiv_right.style.height =  (height + 33) + "px";
		}else {
			contentDiv_right.style.height = height + "px";
			contentDiv.style.height = height + "px";
		}
		leftDiv.style.height = (height ) + "px";
		scrollModel.style.height = (height - 249) + "px";
	} 
	

}catch (ex){}

}











